package com.myChat;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class MySender {
    public static void main(String[] args) {
        System.out.println("你们可以聊天了呀");
        Scanner scanner = new Scanner(System.in);
        DatagramSocket ds = null;
        while (true){
            try {
                InetAddress sIp = InetAddress.getByName("192.168.254.101");
                InetAddress rIp = InetAddress.getByName("192.168.254.101");
                ds = new DatagramSocket(8000,sIp);

                String str = scanner.next();
                DatagramPacket dp = new DatagramPacket(str.getBytes(),str.getBytes().length,rIp,8001);
                ds.send(dp);
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (SocketException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if (ds !=null ){
                    ds.close();
                }
            }
        }

    }
}
